/*
 * Copyright (c) 2024. hallele, Inc All rights reserved.
 */

package cn.hallele.ms.portalcenter.api;

import cn.dev33.satoken.annotation.SaCheckLogin;
import cn.hallele.infrastructure.metadata.io.Page;
import cn.hallele.infrastructure.metadata.io.R;
import cn.hallele.infrastructure.metadata.io.Response;
import cn.hallele.mc.sdk.portalcenter.api.UserApi;
import cn.hallele.mc.sdk.portalcenter.common.constants.ReqPathConst;
import cn.hallele.mc.sdk.portalcenter.dto.UserDTO;
import cn.hallele.mc.sdk.portalcenter.dto.UserQueryDTO;
import cn.hallele.ms.infrastructure.auditlog.annotation.ApiLog;
import cn.hallele.ms.portalcenter.das.UserDBDas;
import jakarta.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * hallele_ms_portalcenter
 *
 * @author anle5
 * @since 2024/10/12 12:31
 */
@RestController
@RequestMapping(ReqPathConst.USER_V1)
public class UserController implements UserApi {
    @Autowired
    private UserDBDas userDBDas;

    /**
     * 获取当前登录用户信息
     *
     * @return UserDTO
     */
    @Override
    @SaCheckLogin
    @ApiLog(id = "USER_V1_ME")
    public Response<UserDTO> me() {
        UserDTO userDTO = userDBDas.me();
        return R.ok(userDTO);
    }

    /**
     * 用户分页查询
     *
     * @param queryParams queryParams
     * @return UserDTO
     */
    @Override
    @ApiLog(id = "USER_V1_PAGE")
    public Response<Page<UserDTO>> page(@Valid UserQueryDTO queryParams) {
        Page<UserDTO> userDTOPage = userDBDas.page(queryParams);
        return R.ok(userDTOPage);
    }
}
